package com.Nahida.NaHome.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.Nahida.NaHome.R;
import com.Nahida.NaHome.activity.base.BaseActivity;
import com.Nahida.NaHome.util.MsgUtil;

public class ShowTextActivity extends BaseActivity {
    int backCount = 0;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_simple_text);

        Intent intent = getIntent();
        String content = intent.getStringExtra("content");

        TextView pagename = findViewById(R.id.pageName);
        pagename.setText(intent.getStringExtra("title"));


        TextView textView = findViewById(R.id.textView);

        if (intent.getData() != null) {
            content = intent.getData().toString();
        }

        textView.setText(content);
    }

    @Override
    public void setTopExit() {
        View view = findViewById(R.id.exit);
        if(view != null) view.setOnClickListener(view1 -> {
            if(!getIntent().getBooleanExtra("disable_back",false)) finish();
            else {
                backCount++;
                if(backCount == 7) finish();
                else MsgUtil.showMsg("点击" + backCount + "/7次确认退出", this);
            }
        });
    }

    @Override
    public void onBackPressed() {
        if(!getIntent().getBooleanExtra("disable_back",false)) finish();
    }
}